<?php

namespace App\Admin\Controllers;

use App\Models\AbductionSlide;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class AbductionSlideController extends AdminController
{
    public function __construct()
    {
        $this -> title = isset($_GET['project_id'])?\App\Models\AbductionProject::where('project_id','=',$_GET['project_id'])
                ->value('project_name').'项目':'';
    }

    protected $title = '项目幻灯片';
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new AbductionSlide(), function (Grid $grid) {
            $grid->AddUrltoCreate("?project_id={$_GET['project_id']}");
            $grid->model()->where('project_id', '=', $_GET['project_id']);
            $grid->actions(function (Grid\Displayers\Actions $actions) {
//                $actions->disableDelete();
//                $actions->disableEdit();
                $actions->disableQuickEdit();
                $actions->disableView();
            });
            $grid->column('slide_id','ID')->sortable();
            $grid->column('slide_title')->editable();
            $grid->column('slide_image')->image('',100,100);
            $grid->column('slide_url','链接');
            $grid->column('slide_sort')->editable()->sortable();
            $grid->column('slide_status','状态')->switch('#333');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('slide_id');

            });
        });
    }


    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new AbductionSlide(), function (Form $form) {
            $project_id = isset($_GET['project_id'])?$_GET['project_id']:'';
            $form->display('slide_id','ID');
            $form->text('slide_title')->required();
            $form->image('slide_image')->required();
            $form->url('slide_url','链接')->required();
            $form->number('slide_sort')->required();
            $form->switch('slide_status','状态')->required();
            $form->hidden('project_id')->value($project_id);
            $form->disableHeader();//去掉上面的
            $form->footer(function ($footer) {

                // 去掉`重置`按钮
                //$footer->disableReset();

                // 去掉`提交`按钮
                //$footer->disableSubmit();

                // 去掉`查看`checkbox
                $footer->disableViewCheck();

                // 去掉`继续编辑`checkbox
                $footer->disableEditingCheck();

                // 去掉`继续创建`checkbox
                $footer->disableCreatingCheck();
            });
            $form->saved(function (Form $form) {
                return $form->response()->success('保存成功')->redirect("abduction_slide?project_id={$form->project_id}");
            });
            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
